package com.tallysystem.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tallysystem.dao.UserDao;
import com.tallysystem.daoimpl.UserDaoImpl;
import com.tallysystem.entity.User;

@WebServlet("/doregisterServlet")
public class RegisterServlet extends HttpServlet{
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		int number = Integer.parseInt(request.getParameter("number"));
		int id = Integer.parseInt(request.getParameter("id"));
		String stuclass = request.getParameter("stuclass");
		String sex = request.getParameter("sex");
		//string 转成 date
		String birth01 = request.getParameter("birth");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
			try {
				date = sdf.parse(birth01);
		       } catch (Exception e) {
		            e.printStackTrace();

		       }
		java.sql.Date birth = new java.sql.Date(date.getTime());
		

		
		//调用接口
		UserDao userDao = new UserDaoImpl();
		userDao.add(new User(username,password,number,id,stuclass,sex,birth));
		response.sendRedirect("login.jsp");
	}
}
